// authStore.ts
import { defineStore } from 'pinia'
import { reactive } from 'vue'
import type { AuthInfo } from '@/types/SharedTypes'


export const useAuthStore = defineStore('auth', {
  state: () => {
    const authState: AuthInfo = reactive<AuthInfo>({
      username: null,
      token: null,
      logged: false
    })

    return {
      ...authState
    }
  },

  actions: {
    login(accessToken: string, username: string) {
      this.username = username
      this.token = accessToken
      this.logged = true
    },

    logout(): void {
      this.username = null
      this.token = null
      this.logged = false
    }
  },

  getters: {
    isLogged: (state) => state.logged,
    getToken: (state) => state.token,
    getUsername: (state) => state.username
  }
})